﻿<Page
    x:Name="PageRoot"
    x:Class="PackageAndDeployExample.MainPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:PackageAndDeployExample"
    xmlns:common="using:PackageAndDeployExample.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="using:Microsoft.Advertising.WinRT.UI"
    mc:Ignorable="d"
    d:DataContext="{d:DesignInstance Type=local:DeploymentViewModel}">

    <Page.Resources>
        <common:BooleanToVisibilityConverter x:Key="IfTrueThenVisible" TrueValue="Visible"/>
        <local:ProductListingSubProductsValueConverter x:Key="ProductListingSubProductsValueConverter"/>
        <local:ProductLicenseLicensesValueConverter x:Key="ProductLicenseLicensesValueConverter"/>
        <Style TargetType="Border" x:Key="BlockBorderStyle">
            <Setter Property="BorderThickness" Value="{StaticResource FlyoutBorderThemeThickness}"/>
            <Setter Property="BorderBrush" Value="{StaticResource FlyoutBorderThemeBrush}"/>
            <Setter Property="Padding" Value="5"/>
            <Setter Property="Margin" Value="5"/>
        </Style>
        <Style TargetType="TextBlock" BasedOn="{StaticResource BodyTextBlockStyle}">
            <Setter Property="Margin" Value="3,0,5,10"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>
        <Style x:Name="DetailsHeaderStyle" TargetType="TextBlock" BasedOn="{StaticResource BodyTextBlockStyle}">
            <Setter Property="Margin" Value="3,0,5,10"/>
            <Setter Property="FontSize" Value="18"/>
            <Setter Property="FontWeight" Value="Bold"/>
        </Style>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Border Grid.Column="0" Style="{StaticResource BlockBorderStyle}">
                <Grid Width="320">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.Resources>
                        <Style TargetType="Button">
                            <Setter Property="HorizontalAlignment" Value="Stretch"/>
                        </Style>
                    </Grid.Resources>
                    <Button Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Content="Reset to Trial" Command="{Binding ResetToTrialCommand}"/>
                    <Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Content="Reset to Full" Command="{Binding ResetToFullCommand}"/>

                    <TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Text="In-App Purchase Items:"/>
                    <ComboBox Grid.Row="3" Grid.Column="0" ItemsSource="{Binding ListingInformation, Converter={StaticResource ProductListingSubProductsValueConverter}}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedProductListing, Mode=TwoWay}"/>
                    <Button Grid.Row="3" Grid.Column="1" Content="Purchase" Command="{Binding PurchaseInAppItemCommand}"/>

                    <StackPanel Grid.Row="99" Grid.Column="0" Grid.ColumnSpan="2" 
                                Margin="10" 
                                Visibility="{Binding LicenseInformation.IsTrial, Converter={StaticResource IfTrueThenVisible}}">
                        <TextBlock Text="Advertisement:" FontWeight="Bold"/>
                        <!-- Using test values for the ApplicationId, AdUnitId values -->
                        <!-- http://msdn.microsoft.com/en-us/library/advertising-windows-test-mode-values(v=msads.10).aspx -->
                        <ui:AdControl ApplicationId="d25517cb-12d4-4699-8bdc-52040c712cab" 
                                      AdUnitId="10043055" 
                                      Width="300" Height="250"/>
                    </StackPanel>
                </Grid>
            </Border>
            <Border Grid.Column="1" Style="{StaticResource BlockBorderStyle}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ScrollViewer Grid.Row="0" VerticalScrollMode="Auto" VerticalScrollBarVisibility="Auto">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="509*"/>
                                <ColumnDefinition Width="376*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Text="Application Details:" Style="{StaticResource DetailsHeaderStyle}"/>

                            <TextBlock Grid.Row="1" Grid.Column="0" Text="App ID:"/>
                            <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding AppId}" Grid.ColumnSpan="2"/>

                            <TextBlock Grid.Row="2" Grid.Column="0" Text="Link:"/>
                            <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding AppLink}" Grid.ColumnSpan="2"/>

                            <TextBlock Grid.Row="3" Grid.Column="0" Text="Name:"/>
                            <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding ListingInformation.Name}" Grid.ColumnSpan="2"/>

                            <TextBlock Grid.Row="4" Grid.Column="0" Text="Description:"/>
                            <TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding ListingInformation.Description}" Grid.ColumnSpan="2"/>

                            <TextBlock Grid.Row="5" Grid.Column="0" Text="Age Rating:"/>
                            <TextBlock Grid.Row="5" Grid.Column="1" Text="{Binding ListingInformation.AgeRating}" Grid.ColumnSpan="2"/>

                            <TextBlock Grid.Row="6" Grid.Column="0" Text="Market:"/>
                            <TextBlock Grid.Row="6" Grid.Column="1" Text="{Binding ListingInformation.CurrentMarket}" Grid.ColumnSpan="2"/>

                            <TextBlock Grid.Row="7" Grid.Column="0" Text="Formatted Price:"/>
                            <TextBlock Grid.Row="7" Grid.Column="1" Text="{Binding ListingInformation.FormattedPrice}" Grid.ColumnSpan="2"/>

                            <TextBlock Grid.Row="8" Grid.Column="0" Text="Product Listings:" Margin="3,25,5,35"/>
                            <ListBox Grid.Row="8" Grid.Column="1" ItemsSource="{Binding ListingInformation, Converter={StaticResource ProductListingSubProductsValueConverter}}" Height="80" Grid.ColumnSpan="2">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Product Listing: " FontWeight="Bold"/>
                                            <TextBlock Text=" ID: "/>
                                            <TextBlock Text="{Binding ProductId}"/>
                                            <TextBlock Text=" Name: "/>
                                            <TextBlock Text="{Binding Name}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>

                            <TextBlock Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="3" Text="License Details:" Style="{StaticResource DetailsHeaderStyle}"/>

                            <TextBlock Grid.Row="10" Grid.Column="0" Text="Is Active:"/>
                            <CheckBox Grid.Row="10" Grid.Column="1" IsChecked="{Binding LicenseInformation.IsActive}" IsEnabled="False" Grid.ColumnSpan="2" Margin="0,2,0,1"/>

                            <TextBlock Grid.Row="11" Grid.Column="0" Text="Is Trial:" Margin="3,2,5,12"/>
                            <StackPanel Grid.Row="11" Grid.Column="1" Orientation="Horizontal" Grid.ColumnSpan="2">
                                <CheckBox IsChecked="{Binding LicenseInformation.IsTrial}" IsEnabled="False"/>

                                <TextBlock Text="Trial Expiration:" Visibility="{Binding LicenseInformation.IsTrial, Converter={StaticResource IfTrueThenVisible}}"/>
                                <TextBlock Text="{Binding LicenseInformation.ExpirationDate}" Visibility="{Binding LicenseInformation.IsTrial, Converter={StaticResource IfTrueThenVisible}}"/>

                                <Button Content="Upgrade to Full" 
                                IsEnabled="{Binding LicenseInformation.IsTrial}" 
                                Command="{Binding UpgradeTrialCommand}"/>
                            </StackPanel>

                            <TextBlock Grid.Row="12" Grid.Column="0" Text="Product Licenses:" Margin="3,25,5,35"/>
                            <ListBox Grid.Row="12" Grid.Column="1" ItemsSource="{Binding LicenseInformation, Converter={StaticResource ProductLicenseLicensesValueConverter}}" Height="80" Grid.ColumnSpan="2">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Product License: " FontWeight="Bold"/>
                                            <TextBlock Text=" ID: "/>
                                            <TextBlock Text="{Binding ProductId}"/>
                                            <TextBlock Text=" Is Active: "/>
                                            <TextBlock Text="{Binding IsActive}"/>
                                            <TextBlock Text=" Expiration: "/>
                                            <TextBlock Text="{Binding ExpirationDate}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </Grid>
                    </ScrollViewer>
                    <StackPanel Grid.Row="1" Visibility="{Binding LicenseInformation.IsTrial, Converter={StaticResource IfTrueThenVisible}}">
                        <TextBlock Text="Advertisement:" Style="{StaticResource DetailsHeaderStyle}"/>
                        <!-- Using test values for the ApplicationId, AdUnitId values -->
                        <!-- http://msdn.microsoft.com/en-us/library/advertising-windows-test-mode-values(v=msads.10).aspx -->
                        <ui:AdControl ApplicationId="d25517cb-12d4-4699-8bdc-52040c712cab" 
                                      AdUnitId="10043000" 
                                      Width="728" Height="90" 
                                      HorizontalAlignment="Center" 
                                      Margin="0,10,0,0"/>
                    </StackPanel>
                </Grid>
            </Border>
        </Grid>

        <!-- Back button and page title -->
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="BackButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}"
                        Style="{StaticResource NavigationBackButtonNormalStyle}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button"/>
            <TextBlock x:Name="PageTitle" Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
        </Grid>
    </Grid>
</Page>
